package cn.schtwz.baseproject.ui

import androidx.fragment.app.Fragment
import cn.schtwz.baselib.base.BaseActivity
import cn.schtwz.baselib.utils.FragmentController
import cn.schtwz.baseproject.R
import cn.schtwz.baseproject.bean.TabEntity
import cn.schtwz.baseproject.databinding.ActivityMainBinding
import cn.schtwz.baseproject.ui.homeEmergency.HomeEmergencyViewModelFragment
import cn.schtwz.baseproject.ui.homeList.HomeListViewModelFragment
import cn.schtwz.baseproject.ui.testFragment.TestFragment
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : BaseActivity<ActivityMainBinding>() {
    private val mTitles = arrayOf("应急", "工作", "应用", "管理")
    private val mTabEntities = ArrayList<CustomTabEntity>()
    private var fragmentController: FragmentController? = null
    private val mIconUnselectIds = intArrayOf(
        R.mipmap.tab_home_unselect,
        R.mipmap.tab_speech_unselect,
        R.mipmap.tab_contact_unselect,
        R.mipmap.tab_more_unselect
    )
    private val mIconSelectIds = intArrayOf(
        R.mipmap.tab_home_select,
        R.mipmap.tab_speech_select,
        R.mipmap.tab_contact_select,
        R.mipmap.tab_more_select
    )
    override val layoutId: Int = R.layout.activity_main


    override fun initView() {
        val fragments = ArrayList<Fragment>()
        fragments.add(HomeEmergencyViewModelFragment())
        fragments.add(TestFragment())
        fragments.add(HomeListViewModelFragment())
        fragments.add(HomeEmergencyViewModelFragment())

        for (i in 0..3) {
            mTabEntities.add(TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]))
        }
        tabLayout.setTabData(mTabEntities)
        fragmentController = FragmentController(this, R.id.fragment, fragments)
        fragmentController?.showFragment(0)
        tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                fragmentController?.showFragment(position)
            }

            override fun onTabReselect(position: Int) {

            }
        })
    }

    override fun initData() {

    }

}
